home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / vect.mli < prev    next >
Encoding:
Text File  |  1993-09-24  |  4.1 KB  |  79 lines  |  [TEXT/MPS ]

  1. (* Operations on vectors *)
  2.  
  3. value vect_length : 'a vect -> int = 1 "vect_length"
  4.         (* Return the length (number of elements) of the given vector. *)
  5. ;;
  6. value vect_item : 'a vect -> int -> 'a
  7.         (* [vect_item v n] returns the element number [n] of vector [v].
  8.            The first element has number 0.
  9.            The last element has number [vect_length v - 1].
  10.            Raise [Invalid_argument "vect_item"]  if [n] is outside the range
  11.            0 -- [(vect_length v - 1)].
  12.            You can also write [v.(n)] instead of [vect_item v n]. *)
  13.   and vect_assign : 'a vect -> int -> 'a -> unit
  14.         (* [vect_assign v n x] modifies vector [v] in place, replacing
  15.            element number [n] with [x].
  16.            Raise [Invalid_argument "vect_assign"] if [n] is outside the range
  17.            0 -- [vect_length v - 1].
  18.            You can also write [v.(n) <- x] instead of [vect_assign v n x]. *)
  19. ;;
  20. value make_vect : int -> 'a -> 'a vect
  21.         (* [make_vect n x] returns a fresh vector of length [n], initialized with [x].
  22.        All the elements of this new vector are initially [eq] to [x]. *)
  23.   and make_matrix : int -> int -> 'a -> 'a vect vect
  24.         (* [make_matrix dimx dimy e] returns a two-dimensional array
  25.            (a vector of vectors) with first dimension [dimx] and
  26.            second dimension [dimy]. All the elements of this new matrix
  27.        are initially [eq] to [e]. The element ([x,y]) of a matrix [m] is accessed
  28.            with the notation [m.(x).(y)]. *)  
  29. ;;
  30. value concat_vect : 'a vect -> 'a vect -> 'a vect
  31.         (* [concat_vect v1 v2] returns a fresh vector containing the
  32.            concatenation of vectors [v1] and [v2]. *)
  33.   and sub_vect : 'a vect -> int -> int -> 'a vect
  34.         (* [sub_vect v start len] returns a fresh vector of length [len],
  35.            containing the elements number [start] to [start + len - 1]
  36.            of vector [v].
  37.            Raise [Invalid_argument "sub_vect"] if [start] and [len] do not
  38.            designate a valid subvector of [v]; that is, if
  39.            [start < 0], or [len < 0], or [start + len > vect_length v]. *)
  40.   and copy_vect : 'a vect -> 'a vect
  41.         (* [copy_vect v] returns a copy of [v], that is, a fresh vector
  42.            containing the same elements as [v]. *)
  43. ;;
  44. value fill_vect : 'a vect -> int -> int -> 'a -> unit
  45.         (* [fill_vect v ofs len x] modifies vector [v] in place,
  46.            storing [x] in elements number [ofs] to [ofs + len - 1].
  47.            Raise [Invalid_argument "fill_vect"] if [ofs] and [len] do not
  48.            designate a valid subvector of [v]. *)
  49.   and blit_vect : 'a vect -> int -> 'a vect -> int -> int -> unit
  50.         (* [blit_vect v1 o1 v2 o2 len] copies [len] elements
  51.            from vector [v1], starting at element number [o1], to vector [v2],
  52.            starting at element number [o2]. It works correctly even if
  53.            [v1] and [v2] are the same vector, and the source and
  54.            destination chunks overlap.
  55.            Raise [Invalid_argument "blit_vect"] if [o1] and [len] do not
  56.            designate a valid subvector of [v1], or if [o2] and [len] do not
  57.            designate a valid subvector of [v2]. *)
  58. ;;
  59. value list_of_vect : 'a vect -> 'a list
  60.         (* [list_of_vect v] returns the list of all the elements of [v], that is:
  61.            [[v.(0); v.(1); ...; v.(vect_length v - 1)]]. *)
  62.   and vect_of_list : 'a list -> 'a vect
  63.         (* [vect_of_list l] returns a fresh vector containing the elements
  64.            of [l]. *)
  65. ;;
  66. value map_vect : ('a -> 'b) -> 'a vect -> 'b vect
  67.         (* [map_vect f v] applies function [f] to all the elements of [v],
  68.            and builds a vector with the results returned by [f]:
  69.            [[| f v.(0); f v.(1); ...; f v.(vect_length v - 1) |]]. *)
  70.   and map_vect_list : ('a -> 'b) -> 'a vect -> 'b list
  71.         (* [map_vect_list f v] applies function [f] to all the elements of [v],
  72.            and builds a list with the results returned by [f]:
  73.            [[ f v.(0); f v.(1); ...; f v.(vect_length v - 1) ]]. *)
  74.   and do_vect : ('a -> 'b) -> 'a vect -> unit
  75.         (* [do_vect f v] applies function [f] in turn to all the elements of [v],
  76.        discarding all the results:
  77.            [f v.(0); f v.(1); ...; f v.(vect_length v - 1); ()]. *)
  78. ;;
  79.